﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<style type="text/css">
    .ui-jqgrid .table-bordered th {
        height: 34px !important;
    }
</style>
<script>
    var currRowId = 1;
    $(function () {
        initControl();
        gridList();
    });
    function initControl() {
        initBindSelect("#form1");
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/BOM/Manufacture/GetProcessRouteCateJson",
            postData: $("#form1").formSerialize(),
            height: $(window).height() - 116,
            colModel: [
                {
                    label: '<a id="grid_chb_selectAll" onclick="grid_chb_selectAll()">全选</a>', name: 'FProductNO', width: 40, align: 'center', sortable: false, frozen: true, formatter: function (cellvalue, options, rowObject) {
                        return '<input class="grid_chb_select" value="' + rowObject.FProductID + '" name="checkbox" type="checkbox" onclick="" style="vertical-align:middle">';
                        //if (rowObject.MaintainStatus == '0') {
                        //    return '<input class="grid_chb_select" value="' + rowObject.FProductNO + '" name="checkbox" type="checkbox" onclick="" disabled="disabled" style="vertical-align:middle">';
                        //} else {
                        //    return '';
                        //}                        
                    }
                },
                { label: '产品编号', name: 'FProductNO', width: 160, align: 'left', sortable: false, frozen: true },
                { label: '产品名称', name: 'FProductName', width: 240, align: 'left', sortable: false, frozen: true },
                { label: '特点概述', name: 'FFeatureExplain', width: 180, align: 'left', sortable: false },
                { label: '参考车型', name: 'FElseExplain', width: 480, align: 'left', sortable: false },
                {
                    label: '明细维护', name: 'FSign', width: 70, align: 'center', sortable: false, formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == '0' ? "否" : cellvalue == '1' ? "是" : "";
                    }
                },
                { label: '产品类型', name: 'FProductClassName', width: 60, align: 'center', sortable: false },
                {
                    label: '审核状态', name: 'MaintainStatus', width: 60, align: 'center', sortable: false, formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == '0' ? "编辑" : cellvalue == '1' ? "审核" : cellvalue == '2' ? "取消" : "";
                    }
                },
                { label: '创建人员', name: 'FCreateBy', width: 70, align: 'left', sortable: false },
                { label: '创建日期', name: 'FCreateDate', width: 80, align: 'center', sortable: false },
                { label: '创建时间', name: 'FCreateTime', width: 80, align: 'center', sortable: false },
                { label: '修改人员', name: 'FUpdateBy', width: 70, align: 'left', sortable: false },
                { label: '修改日期', name: 'FUpdateDate', width: 80, align: 'center', sortable: false },
                { label: '修改时间', name: 'FUpdateTime', width: 80, align: 'center', sortable: false },
                { label: '审核人员', name: 'FAuditingBy', width: 70, align: 'left', sortable: false },
                { label: '审核日期', name: 'FAuditingDate', width: 80, align: 'center', sortable: false },
                { label: '审核时间', name: 'FAuditingTime', width: 80, align: 'center', sortable: false },
                { label: '产品序号', name: 'FOrderNum', width: 20, align: 'center', sortable: false, hidden: true },
                { label: '产品ID', name: 'FProductID', width: 20, align: 'center', sortable: false, hidden: true },
            ],
            pager: "#gridPager",
            sortname: 'FProductNO asc',
            viewrecords: true,  //是否显示行数
            rownumWidth: 40,
            gridComplete: function () {

            },
            loadComplete: function () {
                hackHeight("#gridList");
                $gridList.jqGrid('setSelection', currRowId);
            },
            onSelectRow: function (rowid) {
                currRowId = rowid;
                var rowData = $gridList.jqGrid('getRowData', currRowId);
                $("#FProductID").val(rowData.FProductID);
                //alert($("#FProductID").val());
                $('#btn_edit').removeClass("disabled");
                $('#btn_remove').removeClass("disabled");
            },
            onPaging: function (page_btn) {
                currRowId = 1;
            }
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $gridList.jqGrid('setFrozenColumns');
        $("#btn_search").click(function () {
            reloadGrid();
        });
    }
    function reloadGrid() {
        $("#gridList").jqGrid('setGridParam', {
            postData: $("#form1").formSerialize(),
        }).trigger('reloadGrid');
    }
    function grid_chb_selectAll() {
        var txt = $('#grid_chb_selectAll').text();
        //alert(txt);
        if (txt == "全选") {
            $('.grid_chb_select').prop("checked", true);
            $('#grid_chb_selectAll').text("反选");
        } else {
            $('.grid_chb_select').prop("checked", false);
            $('#grid_chb_selectAll').text("全选");
        }

    }
    function btn_add() {
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/BOM/Manufacture/ProcessRouteCateInput?status=I"
        });
    }
    function btn_remove() {
        var FProductID = $("#FProductID").val();
        if (FProductID == '') {
            $.modalAlert("注：您没有勾选任何数据。", "warning");
        } else {
            $.modalConfirm("注：您确定要【删除】选中行的数据吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/BOM/Manufacture/SubmitProcessRouteCateForm?status=D",
                        param: { keyValue: FProductID },
                        success: function () {
                            reloadGrid();
                        }
                    })
                }
            });
        }
    }
    function btn_edit() {
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/BOM/Manufacture/ProcessRouteCateInput?status=U&number=" + $('#FProductID').val()
        });
    }
    function btn_publish() {
        var chk_value = [];
        $('input[type="checkbox"].grid_chb_select:checked').each(function () {
            chk_value.push($(this).val());
        });
        if (chk_value.length <= 0) {
            $.modalAlert("注：您没有勾选任何数据。", "warning");
        } else {
            //alert(chk_value.join(','));
            $.modalConfirm("注：您确定要【发布】勾选的数据吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/BOM/Manufacture/SubmitProcessRouteCateForm?status=P",
                        param: { keyValue: chk_value.join(',') },
                        success: function () {
                            reloadGrid();
                        }
                    })
                }
            });
        }
    }
    function btn_detail() {
        var chk_value = [];
        $('input[type="checkbox"].grid_chb_select:checked').each(function () {
            chk_value.push($(this).val());
        });
        if (chk_value.length <= 0) {
            $.modalAlert("注：您没有勾选任何数据。", "warning");
        } else {
            //alert(chk_value.join(','));
            $.modalConfirm("注：您确定要将勾选的数据置为可【明细维护】吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/BOM/Manufacture/SubmitProcessRouteCateForm?status=W",
                        param: { keyValue: chk_value.join(',') },
                        success: function () {
                            reloadGrid();
                        }
                    })
                }
            });
        }
    }
    function btn_export() {
        var url = "/Common/ExcelExport?" + init_sql();
        location.href = url;
    }
    function init_sql() {
        var tablename = "V_LXK_11_ML_ProductList";
        var condition = "UseUnit='@FriendStar.Code.Configs.GetValue("UseUnit")'";
        var cols = [];
        //获取列字段
        var colModel = $("#gridList").jqGrid('getGridParam', 'colModel');
        for (var i = 0; i < colModel.length; i++) {
            var columnHidden = colModel[i].hidden;
            var columnName = colModel[i].name;
            var columnLabel = colModel[i].label;
            if (columnHidden == false && columnName != "rn" && columnName != "") {
                if (columnLabel != '') {
                    cols.push(columnName + ' [' + columnLabel.replace(/<[^>]+>/g, "") + ']');
                } else {
                    cols.push(columnName);
                }
            }
        }
        if ($('#FProductNO').val() != '') {
            condition += " AND (FProductNO LIKE '%" + $('#FProductNO').val() + "%')";
        }
        if ($('#FProductName').val() != '') {
            condition += " AND (FProductName LIKE '%" + $('#FProductName').val() + "%')";
        }
        if ($('#FProductClass').val() != '') {
            condition += " AND (FProductClass = '" + $('#FProductClass').val() + "')";
        }
        if ($('#MaintainStatus').val() != '') {
            condition += " AND (MaintainStatus = '" + $('#MaintainStatus').val() + "')";
        }
        var sql = "SELECT " + cols.join(',') + " FROM " + tablename + " WHERE " + condition + " ORDER BY FProductNO ASC";
        return "sql=" + sql;
    }
</script>
<div id="layout" style="height: 100%; width: 100%;">
    <input id="FProductID" name="FProductID" type="hidden" value="" />
    <form id="form1">
        <div id="condition_region" style="padding: 12px 0 5px 0; padding-left:15px; border-bottom:1px solid #ccc;" class="line-table input-width-140">
            <div class="btn-group" style="margin-top:-9px;">
                产品编号<br /><input id="FProductNO" name="FProductNO" type="text" class="form-control" /> &nbsp;
            </div> 
            <div class="btn-group" style="margin-top:-9px;">
                产品名称<br /><input id="FProductName" name="FProductName" type="text" class="form-control" /> &nbsp;
            </div>
            <div class="btn-group input-width-120" style="margin-top:-9px;">
                产品类型<br />
                <select id="FProductClass" name="FProductClass" class="form-control">
                    <option value="">&nbsp;</option>
                    @foreach (var item in ViewBag.productClass)
                    {
                        <option value="@item.FTypeNO">@item.FTypeNO @item.FTypeName</option>
                    }
                </select> &nbsp;
            </div>
            <div class="btn-group input-width-160" style="margin-top:-9px;">
                审核状态<br />
                <select id="MaintainStatus" name="MaintainStatus" class="form-control">
                    <option value="">&nbsp;</option>
                    <option value="0">0-编辑</option>
                    <option value="1">1-审核</option>
                </select> &nbsp;
            </div>
            <div class="btn-group">
                <a id="btn_search" class="btn btn-primary center-block" onclick=""><span class="glyphicon glyphicon-search"></span> 检索</a>
            </div>
            <div class="btn-group" style="float:right;">
                <a id="btn_reload" class="btn btn-primary center-block" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span> 刷新</a>
                <a id="btn_add" class="btn btn-primary center-block" onclick="btn_add()"><span class="glyphicon glyphicon-plus"></span> 新增</a>
                <a id="btn_remove" class="btn btn-primary center-block disabled" onclick="btn_remove()"><span class="glyphicon glyphicon-trash"></span> 删除</a>
                <a id="btn_edit" class="btn btn-primary center-block disabled" onclick="btn_edit()"><span class="glyphicon glyphicon-edit"></span> 修改</a>
                <a id="btn_publish" class="btn btn-primary center-block" onclick="btn_publish()"><span class="glyphicon glyphicon-pencil"></span> 发布</a>
                <a id="btn_detail" class="btn btn-primary center-block" onclick="btn_detail()"><span class="glyphicon glyphicon-pencil"></span> 明细维护</a>                               
                <a id="btn_export" class="btn btn-primary center-block" onclick="btn_export()"><span class="glyphicon glyphicon-download"></span> 导出</a>
            </div>
        </div>
    </form>
    <div id="" style="">
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
</div>

